import carts.*;
import carts.addition.PrisingType;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class PointOfSaleTerminal {
    Map<String, AbstractCart> productMap;
    private PrisingType prisingType = PrisingType.LIBERAL;

    public PointOfSaleTerminal() {
        productMap = prepareProductMap();
    }

    /**
     * Store pricing policy. Liberal by default.
     * @param prisingType pricing policy type
     */
    public void setPricing(PrisingType prisingType) {
        this.prisingType = prisingType;
    }

    public void scan(String product) {
        productMap.get(product).addAnotherOne();
    }

    public BigDecimal calculateTotal() {
        double result = 0;
        for (AbstractCart product : productMap.values()) {
            result += product.calculate(prisingType);
        }
        return BigDecimal.valueOf(result);
    }

    private Map<String, AbstractCart> prepareProductMap() {
        Map<String, AbstractCart> productMap = new HashMap<String, AbstractCart>();
        productMap.put("A", new CartA());
        productMap.put("B", new CartB());
        productMap.put("C", new CartC());
        productMap.put("D", new CartD());
        return productMap;
    }
}
